package com.esfak47.mediafetcher.core.utils;

import com.esfak47.common.job.Job;
import com.esfak47.common.lang.Assert;
import com.esfak47.mediafetcher.core.constants.Constants;
import com.esfak47.mediafetcher.core.event.Event;
import com.esfak47.mediafetcher.core.event.EventGroupEnum;
import com.esfak47.mediafetcher.core.event.EventSender;

/**
 * @author tony
 * @date 2018/5/21
 */
public class JobUtils {

    public static void sendSubmitEvent(EventSender eventSender, Job job) {
        Assert.notNull(eventSender, "eventSender not null");
        eventSender.send(new Event(EventGroupEnum.JOB,
            Constants.JobSubjects.start, job));
    }

    public static void sendCancelEvent(EventSender eventSender, Job job) {
        Assert.notNull(eventSender, "eventSender not null");
        eventSender.send(new Event(EventGroupEnum.JOB,
            Constants.JobSubjects.cancel, job));
    }

    public static void sendFinishedEvent(EventSender eventSender, Job job) {
        Assert.notNull(eventSender, "eventSender not null");
        eventSender.send(new Event(EventGroupEnum.JOB,
            Constants.JobSubjects.finish, job));
    }
    public static void sendDeleteEvent(EventSender eventSender, Job job) {
        Assert.notNull(eventSender, "eventSender not null");
        eventSender.send(new Event(EventGroupEnum.JOB,
            Constants.JobSubjects.delete, job));
    }
    public static void sendErrorEvent(EventSender eventSender, Job job) {
        Assert.notNull(eventSender, "eventSender not null");
        eventSender.send(new Event(EventGroupEnum.JOB,
            Constants.JobSubjects.error, job));
    }

    public static JobLogSender createJobLogSender(String jobId, EventSender eventSender) {
        return new JobLogSender(eventSender, jobId);
    }
}
